package vn.com.vega.chacha.v2;

import vn.com.vega.chacha.R;
import vn.com.vega.music.view.adapter.NewsViewAdapter;
import vn.com.vega.music.view.custom.BottomPlayerView;
import vn.com.vega.music.view.custom.BottomPlayerView.ShowHideBottomPlayerListener;
import vn.com.vega.music.view.custom.TopTaskbarView;
import android.os.Bundle;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.Toast;

public class NewsDetail extends ActivityBase {
	public static final String INDEX_KEY = "index of news";

	private ViewPager mViewPager;
	private NewsViewAdapter mAdapter;
	private Appinstant mApp;
	private TopTaskbarView mTopTaskbarView;
	private BottomPlayerView mBottomPlayer;
	private View mPlayerViewReplace;

	@Override
	protected void onDestroy() {
		// TODO Auto-generated method stub
		super.onDestroy();
	}

	@Override
	protected void onCreate(Bundle arg0) {
		// TODO Auto-generated method stub
		super.onCreate(arg0);
		mApp = (Appinstant) getApplication();
		setContentView(R.layout.news_detail_activity);
		mTopTaskbarView = (TopTaskbarView) findViewById(R.id.topTaskbarView_news_detail);
		mTopTaskbarView.showBackButton();
		
		mViewPager = (ViewPager) findViewById(R.id.paperview_news_detail);
		mAdapter = new NewsViewAdapter(getSupportFragmentManager(),
				mApp.ListNewsFeature);
		mViewPager.setAdapter(mAdapter);

		int indexNews = getIntent().getIntExtra(INDEX_KEY, -1);
		if (indexNews != -1) {
			mViewPager.setCurrentItem(indexNews);
		}
		Toast.makeText(this, getString(R.string.guid_view_news), Toast.LENGTH_LONG).show();
		mPlayerViewReplace = findViewById(R.id.view_replace_bottom_player);
		mBottomPlayer = (BottomPlayerView) findViewById(R.id.bottomPlayerView_new_detail);
		mBottomPlayer.setShowHideListener(showHideBottomPlayerListener);
	}
	
	@Override
	protected void onResume() {
		super.onResume();
		mBottomPlayer.startUpdate();
	}
	
	@Override
	protected void onPause() {
		super.onPause();
		mBottomPlayer.stopUpdate();
	}
	
	ShowHideBottomPlayerListener showHideBottomPlayerListener = new ShowHideBottomPlayerListener() {
		
		@Override
		public void onShowBottomPlayer() {
			// TODO Auto-generated method stub
			mPlayerViewReplace.setVisibility(View.VISIBLE);
		}
		
		@Override
		public void onHideBottomPlayer() {
			// TODO Auto-generated method stub
			mPlayerViewReplace.setVisibility(View.GONE);
		}
	};

}
